package com.springboot.test.springbootcrud.controller;

import com.springboot.test.springbootcrud.exception.UserNotFoundException;
import java.util.Arrays;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/12/15 17:14
 */
@Controller
public class HelloController {

   /* @RequestMapping({"/","/index.html"})
    public String index() {
        return "index";
    }*/

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(@RequestParam("user") String user) {
        if ("aaa".equals(user)) {
            throw new UserNotFoundException();
        }
        return "hello world";
    }

    //查出一些数据在页面展示
    @RequestMapping("/success")
    public String success(Map<String, Object> map) {
        map.put("hello", "<h1>你好</h1>");
        map.put("users", Arrays.asList("zhangsan", "lisi", "wangu"));
        return "success";
    }
}
